Page({
  data: {
    rows: [],
    current: 1
    // pageSize: 3,
    // finished: false
  },
  goDetail({ mark: { id }}) {
    wx.navigateTo({
      url: `/repair_pkg/pages/detail/index?id=${id}`
    })
  },
  addRepair() {
    wx.navigateTo({
      url: '/repair_pkg/pages/form/index'
    })
  },
  // 即时显示保修列表
  onShow() {
    // 显示保修列表并渲染
    this.getRepairList()
  },
  // 获取保修列表
  async getRepairList() {
    const { code, data } = await wx.http.get('repair', {
      current: this.data.current,
      pageSize: 3
    })
    if (code !== 10000) return wx.utils.toast()
    console.log('返回的数据', data)
    const rows = [...this.data.rows, ...data.rows]
    // 更新数据
    this.setData({
      total: data.total,
      rows
    })
    // if (rows.length === data.total) {
    //   this.setData({
    //     finished: true
    //   })
    // }
  },
  bindscrolltolower() {
    if (this.data.rows.length === this.data.total) return wx.utils.toast('暂无更多数据')
    this.setData({
      current: this.data.current + 1
    })
    this.getRepairList()
  }
})
